﻿

using DryIoc;
using KinonekoSoftware.UI;
using NLog;

namespace KinonekoSoftware.Platform
{


    //
    // 下面的代码只负责声明继承关系
    // 没有特殊的作用
    //

    public abstract partial class NativeApplication 
    {
        
        // Ctor
        // ----> Initialize 
        // ----> OnFrameworkInitializationCompleted 
        //
        //
        protected NativeApplication()
        {
            InitializeApplication();
        }
        
        private void InitializeApplication()
        {
            var ai      = GetApplicationFolderInformation();
            var setting = GetOrCreateSetting(ai);
        
            //
            //
            _enableExceptionHandler = setting.EnableExceptionHandler;
        
            //
            // 安装日志记录器
            var logger = InstallLogger(ai, setting);
        
            //
            //
            Ioc.Use<ILogger>(logger);
            Ioc.Use<ApplicationInformation>(ai);
        
            //
            // 安装主题
            Xplat.Theme = InstallTheming(setting);
        
            //
            // 安装语言
            LanguageManager.Language = setting.Language;
        
            //
            // 安装服务
            InstallServicesInternal();
            //
            // 安装视图
            InstallViewAndViewModelsInternal();
        
            //
            // 安装异常处理器
            InstallExceptionHandler();
        }
        
        protected virtual ApplicationInformation GetApplicationFolderInformation()
        {
            return new ApplicationInformation
            {
                ApplicationFolder = AppDomain.CurrentDomain.BaseDirectory,
                GlobalFolder      = AppDomain.CurrentDomain.BaseDirectory,
                EnableLogger      = false,
            };
        }


        #region Settings

        protected virtual ForestSetting GetOrCreateSetting(ApplicationInformation ai)
        {
            return new ForestSetting();
        }

        #endregion

    }

    
   
}